import { loginApi } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    token: getToken()
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    }
  },
  actions: {
    async login(context, data) {
      const res = await loginApi(data)
      context.commit('setToken', res)
      setToken(res)
    }
  }
}
